package com.albaba.designpattern.builder.text_002;

/**
 * @author zx
 * @version 1.0
 * @description TODO
 * @date 2025/2/19 20:47
 */
public class RabbitMQClient_001 {
    private String host = "localhost";

    private int port = 5672;

    private int mode;

    private String exchange;

    private String queue;

    private boolean isDurable = true;

    int connectionTimeout = 1000;

    public RabbitMQClient_001(String host, int port, int mode, String exchange, String queue, boolean isDurable, int connectionTimeout) {
        this.host = host;
        this.port = port;
        this.mode = mode;
        this.exchange = exchange;
        this.queue = queue;
        this.isDurable = isDurable;
        this.connectionTimeout = connectionTimeout;

        if (mode == 1) {
            if (exchange != null) {
                throw new RuntimeException("工作队列模式无需设计交换机");
            }
            if (queue == null || queue.equals("")) {
                throw new RuntimeException("工作队列模式名称不能为空");
            }
            if (!isDurable){
                throw new RuntimeException("工作队列模式必须开启持久化");
            }
        }else if (mode == 2) {
            if (exchange == null || exchange.equals("")) {
                throw new RuntimeException("路由模式下必须设置交换机");
            }
            if (queue != null) {
                throw new RuntimeException("路由模式下不需要设置队列名称");
            }
        }
    }

    public void send(String msg) {
        System.out.println("发送消息：" + msg);
    }

    public static void main(String[] args) {
        RabbitMQClient_001 client = new RabbitMQClient_001("localhost", 5672, 1, null,
                "hello", true, 1000);
        client.send("hello world");
    }
}
